/**************************************************************************
* This file is part of Hawkengine.
**
* Hawkengine is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
**
* Hawkengine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
**
* You should have received a copy of the GNU Lesser General Public License
* along with Hawkengine.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

#ifndef _THREAD_H_
#define _THREAD_H_

/**************************************************************************
* Dependencies
**************************************************************************/
#include "engine/common.h"
 
/**************************************************************************
* Preprocessing
**************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif

/**************************************************************************
* Types
**************************************************************************/
typedef void (*thread_func)(void*);
typedef void* thread_type;
typedef void* thread_mutex_type;
typedef void* thread_rwlock_type;

/**************************************************************************
* Variables
**************************************************************************/

/**************************************************************************
* Static Variables
**************************************************************************/

/**************************************************************************
* Function Prototypes
**************************************************************************/
void thread_create(thread_func func, void* data, BOOL waitable, thread_type* thread);
void thread_create_mutex(thread_mutex_type* mutex);
void thread_create_rwlock(thread_rwlock_type* rwlock);
void thread_destroy_mutex(thread_mutex_type* mutex);
void thread_destroy_rwlock(thread_rwlock_type* rwlock);
void thread_exit(void);
void thread_kill(thread_type* thread);
void thread_lock(thread_mutex_type* mutex);
void thread_lock_read(thread_rwlock_type* rwlock);
void thread_lock_write(thread_rwlock_type* rwlock);
void thread_sleep(int milliseconds);
void thread_unlock(thread_mutex_type* mutex);
void thread_unlock_read(thread_rwlock_type* rwlock);
void thread_unlock_write(thread_rwlock_type* rwlock);
void thread_wait(thread_type* thread);

/**************************************************************************
* Function Implementations
**************************************************************************/


#ifdef __cplusplus
}
#endif

#endif
